package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.EmployOrganizationAddDTO;
import org.jsola.hr.dto.EmployOrganizationUpdateDTO;
import org.jsola.hr.entity.EmployOrganizationDO;
import org.jsola.hr.query.EmployOrganizationQuery;
import org.jsola.hr.service.IEmployOrganizationService;
import org.jsola.hr.vo.EmployOrganizationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 卫人云-用人机构
 *
 * @author zhr
 */
@Component
public class EmployOrganizationTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmployOrganizationService employOrganizationService;

    /**
     * 生成add测试数据
     * @return EmployOrganizationAddDTO
     */
    public EmployOrganizationAddDTO getEmployOrganizationAddDTO(){
        EmployOrganizationAddDTO employOrganizationAddDTO = new EmployOrganizationAddDTO();
        employOrganizationAddDTO.setName(getRandomValue("varchar",50));
        employOrganizationAddDTO.setCity(getRandomValue("varchar",50));
        employOrganizationAddDTO.setAdminName(getRandomValue("varchar",50));
        employOrganizationAddDTO.setAdminUserId(getRandomValue("varchar",32));
        employOrganizationAddDTO.setContactNumber(getRandomValue("varchar",11));
        employOrganizationAddDTO.setOrganizationCode(getRandomValue("varchar",50));
        employOrganizationAddDTO.setBusinessLicense(getRandomValue("varchar",500));
        employOrganizationAddDTO.setOfficeEnvironment(getRandomValue("varchar",1000));
        employOrganizationAddDTO.setAuditState(SafeKit.getInteger(getRandomValue("tinyint",2)));
        return employOrganizationAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmployOrganizationUpdateDTO
     */
    public EmployOrganizationUpdateDTO getEmployOrganizationUpdateDTO(EmployOrganizationVO employOrganizationVO){
        return employOrganizationService.selectDOById(employOrganizationVO.getId(), SITE_ID).to(EmployOrganizationUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmployOrganizationQuery
     */
    public EmployOrganizationQuery getEmployOrganizationQuery() {
        EmployOrganizationQuery employOrganizationQuery = new EmployOrganizationQuery();
        List<EmployOrganizationDO> employOrganizationDOList = employOrganizationService.list(new EmployOrganizationDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(employOrganizationDOList)) {
            EmployOrganizationDO employOrganizationDO = employOrganizationDOList.get(0);
            employOrganizationQuery = employOrganizationDO.to(EmployOrganizationQuery.class);
        }
        return employOrganizationQuery;
    }

    /**
     * 保存示例
     * @return EmployOrganizationVO
     */
    public EmployOrganizationVO saveEmployOrganizationExample(){
        EmployOrganizationAddDTO addDTO = this.getEmployOrganizationAddDTO();
        EmployOrganizationVO employOrganizationVO = employOrganizationService.save(addDTO,buildTokenUser());
        return employOrganizationVO;
    }


}

